public class Compare {
    // 比较版本号
    // https://www.nowcoder.com/practice/2b317e02f14247a49ffdbdba315459e7?tpId=295&tags=&title=&difficulty=0&judgeStatus=0&rp=0&sourceUrl=%2Fexam%2Foj%3FquestionJobId%3D10%26subTabName%3Donline_coding_page
    public int compare (String version1, String version2) {
        // write code here
        String[] s1 = version1.split("\\.");
        String[] s2 = version2.split("\\.");
        for (int i = 0; i < Math.max(s1.length, s2.length); i++) {
            if (i >= s1.length) {
                if (Integer.valueOf(s2[i]) != 0) {
                    return -1;
                }
            } else if (i >= s2.length) {
                if (Integer.valueOf(s1[i]) != 0) {
                    return 1;
                }
            } else {
                int num1 = Integer.valueOf(s1[i]);
                int num2 = Integer.valueOf(s2[i]);
                if (num1 > num2) {
                    return 1;
                } else if (num1 < num2){
                    return -1;
                }
            }
        }
        return 0;
    }

    public static void main(String[] args) {
        Compare compare = new Compare();
        System.out.println(compare.compare("1.0.1", "1"));
    }
}
